package com.cskaoyan.controller;


import com.cskaoyan.bean.Comment;
import com.cskaoyan.service.CommentServiceImpl;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.vo.CommentListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CommentController {

    @Autowired
    CommentServiceImpl commentService;

    /**
     * 作者：grz
     * 功能：获取评论列表
     * @param page 页数
     * @param sort 排列方式
     * @param order 正序倒序
     * @param limit 条目数
     * @param userId 用户id
     * @param valueId 商品id
     * @return BaseRespVo
     */
    @RequestMapping("/admin/comment/list")
    public BaseRespVo list(Integer page,Integer limit,String sort,String order,Integer userId,Integer valueId){

        CommentListVo commentListVo = commentService.list(page,limit,sort,order,userId,valueId);

        return BaseRespVo.ok(commentListVo);
    }

    /**
     * 作者：grz
     * 功能：删除评论
     * @param comment
     * @return BaseRespVo
     */
    @RequestMapping("/admin/comment/delete")
    public BaseRespVo delete(@RequestBody Comment comment){

        int i = commentService.delete(comment);

        if(i==404){
            return BaseRespVo.error("删除评论失败");
        }
        return BaseRespVo.ok("删除评论成功");
    }
}
